package com.zues.thread.design_mode.guarded_stop;

import lombok.extern.slf4j.Slf4j;

/**
 * 邮递员类
 */
@Slf4j(topic = "c.Postman")
public class Postman extends Thread{

    private Integer id;
    private String mail;

    public Postman(Integer id, String mail) {
        this.id = id;
        this.mail = mail;
    }

    @Override
    public void run() {
        //送信
        GuardedObject guardedObject = MailBoxes.getGuardedObject(id);
        if(guardedObject == null){
            log.debug("没有收信人，丢弃");
            return;
        }
        log.debug("送信 id: {}, 内容：{}",id,mail);
        guardedObject.complete(mail);


    }

}
